package cn.net.yugu.doraemon.netty.protocol.msg24;

import cn.net.yugu.doraemon.netty.protocol.MsgCode;
import io.netty.buffer.ByteBuf;

/**
 * 柜子心跳转发
 */
public class Msg241000002 extends Msg241 {
    public int time;
    public String cabinetId;
    public int heartType;
    public String json;

    @Override
    public int getMsgCode() {
        return MsgCode.MSG_241000002.getCode();
    }

    @Override
    public void readData(ByteBuf buffer) {
        cabinetId = readString(buffer);
        heartType = buffer.readInt();
        json = readString(buffer);
    }

    @Override
    public void writeData(ByteBuf buffer) {
        writeString(buffer, cabinetId);
        buffer.writeInt(heartType);
        writeString(buffer, json);
    }

    public String getCabinetId() {
        return cabinetId;
    }

    @Override
    public void writeTime(ByteBuf buffer) {
        String timestamp = String.valueOf(System.currentTimeMillis()/1000);
        buffer.writeInt(Integer.parseInt(timestamp));
    }

    @Override
    public void readTime(ByteBuf buffer) {
        time = buffer.readInt();
    }
}
